import CryptoJS from 'crypto-js'

export const GDMusicEncrypt = (message: string): string => {
  if (!message) return ''
  message = encodeURIComponent(String(message))
  const requestDomain = import.meta.env.VITE_GDMUSIC_REQUEST_DOMAIN
  const version = String(import.meta.env.VITE_GDMUSIC_VERSION).replaceAll('.', '')
  const timestamp = String(Date.now()).slice(0, 9)
  const plaintext = `${requestDomain}|${version}|${timestamp}|${message}`
  const cypherText = CryptoJS.MD5(plaintext).toString()
  const cypherTextSlice = cypherText.slice(-8).toUpperCase()
  console.log(plaintext, cypherTextSlice)
  return cypherTextSlice
}